<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <include file="Public/meta" />
</head>
<body>
    <div class="info-center">
        <div class="page-header">
            <div class="pull-left">
                <h4>菜单列表</h4>      
            </div>
            <a href="javascript:;" onclick="add()" class="btn btn-primary pull-right margin-top">添加菜单</a>
        </div>
        <div class="clearfix"></div>
        <div class="table-margin">
            <table class="table table-hover table-header" id="list-table">
                <thead>
                    <tr>
                        <td>菜单名称</td>
                        <td>链接</td>
                        <td>排序</td>
                        <td class="w10">操作</td>
                    </tr>
                </thead>
                <tbody>
                    <foreach name="data" item="vo">
                        <tr>
                            <td>{$vo['_name']}</td>
                            <td>
                                {$vo['mca']}
                            </td>
                            <td>
                                <input type="text"
                                       onchange="updateSort('adminNav','id','{$vo.id}','order_number',this)"
                                       onkeyup="this.value=this.value.replace(/[^\d]/g,'')"
                                       onpaste="this.value=this.value.replace(/[^\d]/g,'')"
                                       size="4"
                                       value="{$vo.order_number}"
                                   class="form-control" style="width:80px" />
                            </td>
                            <td>
                                <if condition="$vo['pid'] eq 0">
                                    <a href="javascript:;" navid="{$vo['id']}" navname="{$vo['name']}" onclick="add_child(this)">添加子菜单</a>
                                    <span class="text-explode">|</span>
                                </if>
                                <a href="javascript:;" navid="{$vo['id']}" navname="{$vo['name']}" navmca="{$vo['mca']}" navico="{$vo['ico']}" onclick="edit(this)"> 编辑</a>
                                <span class="text-explode">|</span>
                                <a href="javascript:if(confirm('确定删除？'))location='{:U('Admin/Nav/delete',array('id'=>$vo['id']))}'" >删除</a>
                            </td>
                        </tr>
                    </foreach>
                </tbody>
            </table>
        </div>
    </div> 
    <div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel"> 添加菜单</h4>
                </div>
                <div class="modal-body">
                    <form id="bjy-form" class="form-horizontal" action="{:U('Admin/Nav/add')}" method="post">
                        <input type="hidden" name="pid" value="0">
                        <table class="table table-hover contact-template-form">
                            <tbody><tr>
                                <td width="20%" align="right">菜单名：</td>
                                <td>
                                    <input class="form-control w-300" type="text" name="name">
                                </td>
                            </tr>
                            <tr>
                                <td width="20%" align="right">连接：</td>
                                <td>
                                    <input class="form-control w-300" type="text" name="mca">
                                    一级菜单：模块/控制器 如：Admin/Nav
                                    <br/>
                                    二级菜单：模块/控制器/方法 如：Admin/Nav/index
                                </td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary" type="submit" value="添加">
                                </td>
                            </tr>
                        </tbody></table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel"> 修改菜单</h4>
                </div>
                <div class="modal-body">
                    <form id="bjy-form" class="form-horizontal" action="{:U('Admin/Nav/edit')}" method="post">
                        <input type="hidden" name="id">
                        <table class="table table-hover contact-template-form">
                            <tbody><tr>
                                <td width="20%" align="right">菜单名：</td>
                                <td>
                                    <input class="form-control w-300" type="text" name="name">
                                </td>
                            </tr>
                            <tr>
                                <td width="20%" align="right">连接：</td>
                                <td>
                                    <input class="form-control w-300" type="text" name="mca">
                                    一级菜单：模块/控制器 如：Admin/Nav
                                    <br/>
                                    二级菜单：模块/控制器/方法 如：Admin/Nav/index
                                </td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary" type="submit" value="修改">
                                </td>
                            </tr>
                        </tbody></table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="__ADMIN_JS__/common.js"></script>
    <script>
    // 添加菜单
    function add(){
        $("input[name='name'],input[name='mca']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj){
        var navId=$(obj).attr('navId');
        $("input[name='pid']").val(navId);
        $("input[name='name']").val('');
        $("input[name='mca']").val('');
        $("input[name='ico']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var navId=$(obj).attr('navId');
        var navName=$(obj).attr('navName');
        var navMca=$(obj).attr('navMca');
        var navIco=$(obj).attr('navIco');
        $("input[name='id']").val(navId);
        $("input[name='name']").val(navName);
        $("input[name='mca']").val(navMca);
        $("input[name='ico']").val(navIco);
        $('#bjy-edit').modal('show');
    }

    </script>
</body>
</html>
